import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-03-21
 * Time: 15:08
 */
public class JDBCDeleteDemo {
    public static void main(String[] args) throws SQLException {
        // 1. 创建资源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/java0321?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("lyf2021");

        // 2. 建立连接
        Connection connection = dataSource.getConnection();

        // 3. 构造 sql
        String sql = "delete from student where id = 3";
        PreparedStatement statement = connection.prepareStatement(sql);

        // 4. 执行sql
        int ret = statement.executeUpdate();
        System.out.println(ret);
        // 5. 关闭资源
        statement.close();
        connection.close();
    }

}
